package org.monitor.demo.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.monitor.demo.pojo.DiskInfo;
import org.monitor.demo.pojo.MemoryInfo;
import org.monitor.demo.service.DiskService;
import org.monitor.demo.service.MemoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/misc")
public class MiscController {

	public MiscController() {
		// TODO Auto-generated constructor stub
	}
	
	@RequestMapping("/void")
	public void useVoid(HttpServletResponse response) throws IOException {
		response.getWriter().println("Test void void");
		response.getWriter().println(new Date());
	}
	
	@RequestMapping("/modelAndView")
	public ModelAndView testMAV() {
		//如果没有指定new ModelAndView()
		//就是正式的url，比如/WEB-INF/jsp/misc/modelAndView.jsp
		ModelAndView mav = new ModelAndView("diskInfo");
		List<DiskInfo> list = (new DiskService()).getDiskInfo();
//		model.addAttribute("diskInfo", list);
		mav.addObject("diskInfo", list);
		return mav;
	}
	
	@RequestMapping("/json")
//	@ResponseBody
	public @ResponseBody MemoryInfo minfo() {
		//通过在accept头里指定content type，来实现返回json或者xml
		//application/json,  application/xml
		MemoryInfo info = (new MemoryService()).getMemoryInfo();
		return info;
	}
}
